package cn.new7as.cas5s.ui.record;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.new7as.cas5s.R;
import cn.new7as.cas5s.ui.easy.netapi.RecordsApi;

public class ReplyAdapter extends BaseAdapter {

    private List<RecordsApi.Datas> list;
    private Activity context;


    public ReplyAdapter(List<RecordsApi.Datas> list, Activity context) {
        super();

        this.context = context;
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {

           convertView= LayoutInflater.from(context).inflate(R.layout.layout_grid_reply, parent,false);



            viewHolder = new ViewHolder();
            viewHolder.sendtime = (TextView) convertView.findViewById(R.id.sendtime);
            viewHolder.replycontent = (TextView) convertView.findViewById(R.id.replycontent);
            viewHolder.view = (View) convertView.findViewById(R.id.view);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (position == list.size() - 1)
            viewHolder.view.setVisibility(View.INVISIBLE);
        else
            viewHolder.view.setVisibility(View.VISIBLE);
        RecordsApi.Datas dataBean = list.get(position);
        viewHolder.sendtime.setText(dataBean.replyDate);
        viewHolder.replycontent.setText(dataBean.replyContent);
        return convertView;
    }

    static class ViewHolder {
        TextView sendtime;
        TextView replycontent;
        View view;

    }
}
